﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class MovementBLL
    {
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IInvLotDA invLotDA = DataAccess.CreateInvLotDA();
        private static readonly IInvLotLocLpnDA invLotLocLpnDa = DataAccess.CreateInvLotLocLpnDA();
        private static readonly IInvSkuLocDA invSkuLocDA = DataAccess.CreateInvSkuLocDA();
        private static readonly ILocationDA locationDA = DataAccess.CreateLocationDA();
        private static readonly ILpnDA lpnDA = DataAccess.CreateLpnDA();
        private static readonly IManPowerResourceDA manpowerResourceDA = DataAccess.CreateManPowerResourceDA();
        private static readonly IMovementDA movementDA = DataAccess.CreateMovementDA();
        private static readonly IMovementDetailDA movementDetailDA = DataAccess.CreateMovementDetailDA();
        private static readonly IOwnerDA ownerDA = DataAccess.CreateOwnerDA();
        private PubParasInfo pubParasInfo;
        private static readonly ITaskDetailDA taskDetailDA = DataAccess.CreateTaskDetailDA();

        public MovementBLL()
        {
            this.pubParasInfo = null;
        }

        public MovementBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public MovementBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string AllocateMovement(string movementID)
        {
            string result = string.Empty;
            if (!string.IsNullOrEmpty(movementID))
            {
                string updatedBy = this.pubParasInfo.UserID;
                string whLoginID = this.dataBaseID[0];
                List<MovementDetailInfo> movementDetailInfos = movementDetailDA.GetMovementDetailByID(movementID, whLoginID, this.pubParasInfo);
                if ((movementDetailInfos == null) || (movementDetailInfos.Count <= 0))
                {
                    throw new Exception("未找到匹配的明细进行分配！");
                }
                DataBase dataBase = new DataBase();
                DbConnection conn = dataBase.connection;
                conn.Open();
                DbTransaction tran = conn.BeginTransaction();
                try
                {
                    for (int i = 0; i < movementDetailInfos.Count; i++)
                    {
                        InvLotInfo invLotinfo = new InvLotInfo {
                            Lot = movementDetailInfos[i].Lot,
                            UpdatedBy = updatedBy,
                            PickedQty = movementDetailInfos[i].Qty,
                            AllocatedGrossWgt = 0.0,
                            AllocatedNetWgt = 0.0
                        };
                        invLotDA.UpdateInvLot(dataBase, tran, invLotinfo, InvLotUpdateType.PickedQtyOnly, whLoginID);
                        InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                            Lot = movementDetailInfos[i].Lot,
                            Loc = movementDetailInfos[i].FromLoc,
                            LpnID = movementDetailInfos[i].FromLpnID,
                            PickedQty = movementDetailInfos[i].Qty,
                            UpdatedBy = updatedBy
                        };
                        invLotLocLpnDa.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.PickedQtyOnly, whLoginID);
                        InvSkuLocInfo invskulocInfo = new InvSkuLocInfo {
                            Loc = movementDetailInfos[i].FromLoc,
                            SkuID = movementDetailInfos[i].SkuID,
                            OwnerID = movementDetailInfos[i].OwnerID,
                            UpdatedBy = updatedBy,
                            PickedQty = movementDetailInfos[i].Qty
                        };
                        invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.PickedQtyOnly, whLoginID);
                        TaskDetailInfo taskDetailEntity = new TaskDetailInfo {
                            TaskDetailID = commonMethod.GenNextNumStr("TASK_DETAIL", whLoginID),
                            TaskType = TaskType.MV,
                            OwnerID = movementDetailInfos[i].OwnerID,
                            SkuID = movementDetailInfos[i].SkuID,
                            Lot = movementDetailInfos[i].Lot,
                            UomID = movementDetailInfos[i].UomID,
                            Qty = movementDetailInfos[i].Qty,
                            FromLoc = movementDetailInfos[i].FromLoc,
                            LogicalFromLoc = movementDetailInfos[i].FromLoc,
                            FromLpnID = movementDetailInfos[i].FromLpnID,
                            ToLoc = movementDetailInfos[i].ToLoc,
                            LogicalToLoc = movementDetailInfos[i].ToLoc,
                            ToLpnID = movementDetailInfos[i].ToLpnID,
                            CaseID = "",
                            PickMethod = "",
                            Status = TaskStatus.Pending,
                            StatusMsg = "",
                            Priority = TaskPriority.five,
                            SourcePriority = "",
                            HoldID = "",
                            UserID = "",
                            UserPosition = "",
                            UserIdOverride = "",
                            StartTime = DateTime.Now,
                            EndTime = DateTime.Now,
                            SourceType = "",
                            DocID = movementDetailInfos[i].MovementID,
                            DocLineID = movementDetailInfos[i].LineID,
                            PickDetailID = "",
                            OrderID = "",
                            OrderLineID = 0,
                            ListID = "",
                            WaveID = "",
                            ReasonID = "",
                            Message01 = "",
                            Message02 = "",
                            Message03 = "",
                            FinalToLoc = "",
                            FromTransID = "",
                            ToTransID = "",
                            CreatedBy = this.pubParasInfo.UserID,
                            UpdatedBy = this.pubParasInfo.UserID
                        };
                        taskDetailDA.InsertTaskDetail(dataBase, tran, taskDetailEntity, whLoginID);
                    }
                    movementDA.UpdateMovementStatus(dataBase, tran, "Allocated", movementID, this.pubParasInfo.UserID, whLoginID);
                    movementDetailDA.UpdateMovementDetailStatus(dataBase, tran, movementID, "Allocated", whLoginID);
                    tran.Commit();
                    result = movementID;
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
            return result;
        }

        public string Delete(List<string> IDS)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string temp = string.Empty;
            try
            {
                List<MovementInfo> MovementInfos = new List<MovementInfo>();
                MovementInfo contractInfo = null;
                foreach (string id in IDS)
                {
                    contractInfo = movementDA.GetMovementByID(dataBase, tran, id, this.dataBaseID[0]);
                    MovementInfos.Add(contractInfo);
                }
                AuditDataBLL auditDataBLL = new AuditDataBLL();
                movementDetailDA.DeleteMovementDetail(dataBase, tran, IDS, this.dataBaseID[0]);
                if (movementDA.DeleteMovement(dataBase, tran, IDS, this.dataBaseID[0]) > 0)
                {
                    int i;
                    List<string> orderType = new List<string>();
                    List<string> orderID = new List<string>();
                    for (i = 0; i < IDS.Count; i++)
                    {
                        orderType.Add("MV");
                        orderID.Add(IDS[i]);
                    }
                    manpowerResourceDA.DeleteManPowerResource(dataBase, tran, orderID, orderType, this.dataBaseID[0]);
                    for (i = 0; i < IDS.Count; i++)
                    {
                        auditDataBLL.InsertAuditData<MovementInfo>(dataBase, tran, MovementInfos[i], null, AuditAction.Delete, this.pubParasInfo.UserID, "MOVEMENT", this.dataBaseID[0]);
                        temp = temp + IDS[i] + ",";
                    }
                    temp = temp.Substring(0, temp.Length - 1);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public MovementInfo GetInfoByID(string id)
        {
            MovementInfo movementInfo = movementDA.GetMovementByID(id, this.dataBaseID[0]);
            if (movementInfo != null)
            {
                movementInfo.MovementDetailInfos = movementDetailDA.GetMovementDetailByID(id, this.dataBaseID[0], this.pubParasInfo);
            }
            return movementInfo;
        }

        public DataSet GetInfoByQueryEntity(MovementQueryEntity movementQueryEntity)
        {
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(movementQueryEntity.MovementID))
            {
                sqlWhere.Add(" MOVEMENT_ID " + movementQueryEntity.MovementID);
            }
            if (!string.IsNullOrEmpty(movementQueryEntity.MovementType))
            {
                sqlWhere.Add(" MOVEMENT_TYPE " + movementQueryEntity.MovementType);
            }
            if (!string.IsNullOrEmpty(movementQueryEntity.ReasonCode))
            {
                sqlWhere.Add(" REASON_CODE " + movementQueryEntity.ReasonCode);
            }
            if (!string.IsNullOrEmpty(movementQueryEntity.MovementDate))
            {
                sqlWhere.Add(movementQueryEntity.MovementDate.Replace("@MovementDate@", "MOVEMENT_DATE"));
            }
            if (!string.IsNullOrEmpty(movementQueryEntity.Status))
            {
                sqlWhere.Add(" STATUS " + movementQueryEntity.Status);
            }
            return movementDA.GetMovementByQueryList(sqlWhere, movementQueryEntity, this.dataBaseID[0], this.pubParasInfo);
        }

        public DataSet GetMovementAllInfo()
        {
            return movementDA.GetAllMovement(this.dataBaseID[0]);
        }

        public string Insert(MovementInfo movementInfo)
        {
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string strMovementID = string.Empty;
            try
            {
                if (!ownerDA.CheckTradePartnerIDUnique(movementInfo.OwnerID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F4200_004", this.pubParasInfo.UserLanguage, new List<string> { movementInfo.OwnerID });
                }
                else if (!commonMethod.CheckAuthorizationOwnerByUserID(this.pubParasInfo.UserID, movementInfo.OwnerID))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F4200_005", this.pubParasInfo.UserLanguage, new List<string> { movementInfo.OwnerID });
                }
                if (string.IsNullOrEmpty(movementInfo.MovementID))
                {
                    movementInfo.MovementID = commonMethod.GenNextNumStr(dataBase, tran, "MOVEMENT", whLoginID);
                }
                movementInfo.UpdatedBy = movementInfo.CreatedBy;
                movementInfo.CreatedDate = DateTime.Now;
                movementInfo.UpdatedDate = DateTime.Now;
                if (movementDA.InsertMovement(dataBase, tran, movementInfo, whLoginID) > 0)
                {
                    strMovementID = movementInfo.MovementID;
                    movementInfo.ManPowerResourceInfo.OrderID = movementInfo.MovementID;
                    movementInfo.ManPowerResourceInfo.CreatedDate = DateTime.Now;
                    movementInfo.ManPowerResourceInfo.UpdatedDate = DateTime.Now;
                    ManPowerResourceInfo manpowerResourceInfo = movementInfo.ManPowerResourceInfo;
                    manpowerResourceDA.InsertManPowerResource(dataBase, tran, manpowerResourceInfo, this.dataBaseID[0]);
                    new AuditDataBLL().InsertAuditData<MovementInfo>(dataBase, tran, null, movementInfo, AuditAction.Insert, this.pubParasInfo.UserID, "MOVEMENT", this.dataBaseID[0]);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return strMovementID;
        }

        public string MovementClose(List<string> movementID)
        {
            int i;
            List<BillingCredenceInfo> billingCredenceListInfo;
            string strtemp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            BillingOrderBLL billingOrderBLL = new BillingOrderBLL(this.pubParasInfo);
            Dictionary<string, List<BillingCredenceInfo>> billingCredenceListObjects = new Dictionary<string, List<BillingCredenceInfo>>();
            for (i = 0; movementID.Count > i; i++)
            {
                billingCredenceListInfo = billingOrderBLL.GetMovementBillingCredenceListInfo(movementID[i]);
                billingCredenceListObjects.Add(movementID[i], billingCredenceListInfo);
            }
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (i = 0; movementID.Count > i; i++)
                {
                    movementDA.UpdateMovementStatus2(dataBase, tran, "Closed", movementID[i], this.pubParasInfo.UserID, this.dataBaseID[0]);
                    if (billingCredenceListObjects.ContainsKey(movementID[i]))
                    {
                        billingCredenceListInfo = new List<BillingCredenceInfo>();
                        billingCredenceListObjects.TryGetValue(movementID[i], out billingCredenceListInfo);
                        billingOrderBLL.GenerateBillingCredenceByCloseOrder(dataBase, tran, movementID[i], "Movement", billingCredenceListInfo);
                    }
                    strtemp = strtemp + movementID[i] + " ;";
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return strtemp;
        }

        public string MovementConfirm(string movementID)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            List<MovementDetailInfo> movementDetailInfos = movementDetailDA.GetMovementDetailByID(movementID, whLoginID, this.pubParasInfo);
            if ((movementDetailInfos != null) && (movementDetailInfos.Count > 0))
            {
                DataBase dataBase = new DataBase();
                DbConnection conn = dataBase.connection;
                conn.Open();
                DbTransaction tran = conn.BeginTransaction();
                try
                {
                    InboundHelper inboundHelper = new InboundHelper();
                    InventoryMgtBLL inventoryMgt = new InventoryMgtBLL(this.pubParasInfo);
                    for (int i = 0; i < movementDetailInfos.Count; i++)
                    {
                        InvLotLocLpnInfo invLotLocLpnInfo = invLotLocLpnDa.GetInvLotLocLpnByID(dataBase, tran, movementDetailInfos[i].Lot, movementDetailInfos[i].FromLoc, movementDetailInfos[i].FromLpnID, whLoginID);
                        if (invLotLocLpnInfo == null)
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F5050_015", this.pubParasInfo.UserLanguage, new List<string> { movementDetailInfos[i].SkuID, movementDetailInfos[i].Lot, movementDetailInfos[i].FromLoc });
                        }
                        else
                        {
                            if (invLotLocLpnInfo.Status == InvHoldStatus.HOLD)
                            {
                            }
                            if (invLotLocLpnInfo.Qty < movementDetailInfos[i].Qty)
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F5050_016", this.pubParasInfo.UserLanguage, new List<string> { movementDetailInfos[i].SkuID, movementDetailInfos[i].Lot, movementDetailInfos[i].FromLoc });
                            }
                        }
                        if (!locationDA.CheckLocationIDUnique(dataBase, tran, movementDetailInfos[i].ToLoc, whLoginID))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F5050_001", this.pubParasInfo.UserLanguage);
                        }
                        InvMovesInfo invMovesInfo = new InvMovesInfo {
                            FromLoc = movementDetailInfos[i].FromLoc,
                            FromLot = movementDetailInfos[i].Lot,
                            FromLpn = movementDetailInfos[i].FromLpnID,
                            FromMoveQty = movementDetailInfos[i].Qty,
                            FromOwnerID = movementDetailInfos[i].OwnerID,
                            FromPackID = movementDetailInfos[i].PackID,
                            FromSkuID = movementDetailInfos[i].SkuID,
                            FromUomID = movementDetailInfos[i].UomID,
                            MoveQty = movementDetailInfos[i].Qty,
                            PackID = movementDetailInfos[i].PackID,
                            ToLoc = movementDetailInfos[i].ToLoc,
                            ToLot = movementDetailInfos[i].Lot,
                            ToLpn = movementDetailInfos[i].ToLpnID,
                            ToOwnerID = movementDetailInfos[i].OwnerID,
                            ToSkuID = movementDetailInfos[i].SkuID,
                            UomID = movementDetailInfos[i].UomID,
                            UpdatedBy = this.pubParasInfo.UserID
                        };
                        inventoryMgt.UpdateInvLotLocLpn4Moves(dataBase, tran, invMovesInfo, InvMoveType.OwnerTransfer, whLoginID);
                        inventoryMgt.UpdateInvSkuLoc4Moves(dataBase, tran, invMovesInfo, InvMoveType.OwnerTransfer, whLoginID);
                        inventoryMgt.UpdateLpn4Moves(dataBase, tran, invMovesInfo, whLoginID);
                        inventoryMgt.UpdateInvLot4Moves(dataBase, tran, invMovesInfo, InvMoveType.OwnerTransfer, whLoginID);
                        string transID = inventoryMgt.InsertInvMovesTrans(dataBase, tran, invMovesInfo, TransSourceType.ConsoleMove, whLoginID);
                        temp = temp + transID + ",";
                        TaskDetailInfo taskDetailInfo = taskDetailDA.GetTaskDetailInfoByDocAndLineID(dataBase, tran, movementDetailInfos[i].MovementID, movementDetailInfos[i].LineID.ToString(), TaskType.MV, whLoginID, this.pubParasInfo);
                        if (taskDetailInfo != null)
                        {
                            taskDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                            taskDetailInfo.UpdatedDate = DateTime.Now;
                            taskDetailInfo.FinalToLoc = movementDetailInfos[i].ToLoc;
                            taskDetailInfo.FromTransID = "";
                            taskDetailInfo.ToTransID = transID;
                            taskDetailInfo.Status = TaskStatus.Completed;
                            taskDetailDA.UpdateTaskDetail(dataBase, tran, taskDetailInfo, whLoginID);
                        }
                    }
                    movementDA.UpdateMovementStatus(dataBase, tran, "Complete", movementID, this.pubParasInfo.UserID, whLoginID);
                    movementDetailDA.UpdateMovementDetailStatus(dataBase, tran, movementID, "Complete", whLoginID);
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
            return temp;
        }

        public string RevertAllocateMovement(string movementID)
        {
            string result = string.Empty;
            if (!string.IsNullOrEmpty(movementID))
            {
                string whLoginID = this.dataBaseID[0];
                string updatedBy = this.pubParasInfo.UserID;
                List<MovementDetailInfo> movementDetailInfos = movementDetailDA.GetMovementDetailByID(movementID, whLoginID, this.pubParasInfo);
                DataBase dataBase = new DataBase();
                DbConnection conn = dataBase.connection;
                conn.Open();
                DbTransaction tran = conn.BeginTransaction();
                try
                {
                    if ((movementDetailInfos != null) && (movementDetailInfos.Count > 0))
                    {
                        for (int i = 0; i < movementDetailInfos.Count; i++)
                        {
                            InvLotInfo invLotinfo = new InvLotInfo {
                                Lot = movementDetailInfos[i].Lot,
                                UpdatedBy = updatedBy,
                                PickedQty = movementDetailInfos[i].Qty * -1M,
                                AllocatedGrossWgt = 0.0,
                                AllocatedNetWgt = 0.0
                            };
                            invLotDA.UpdateInvLot(dataBase, tran, invLotinfo, InvLotUpdateType.PickedQtyOnly, whLoginID);
                            InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                                Lot = movementDetailInfos[i].Lot,
                                Loc = movementDetailInfos[i].FromLoc,
                                LpnID = movementDetailInfos[i].FromLpnID,
                                PickedQty = movementDetailInfos[i].Qty * -1M,
                                UpdatedBy = updatedBy
                            };
                            invLotLocLpnDa.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.PickedQtyOnly, whLoginID);
                            InvSkuLocInfo invskulocInfo = new InvSkuLocInfo {
                                Loc = movementDetailInfos[i].FromLoc,
                                SkuID = movementDetailInfos[i].SkuID,
                                OwnerID = movementDetailInfos[i].OwnerID,
                                UpdatedBy = updatedBy,
                                PickedQty = movementDetailInfos[i].Qty * -1M
                            };
                            invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.PickedQtyOnly, whLoginID);
                        }
                    }
                    taskDetailDA.DeleteTaskDetailByDocID(dataBase, tran, movementID, whLoginID);
                    movementDA.UpdateMovementStatus(dataBase, tran, "New", movementID, this.pubParasInfo.UserID, whLoginID);
                    movementDetailDA.UpdateMovementDetailStatus(dataBase, tran, movementID, "New", whLoginID);
                    tran.Commit();
                    result = movementID;
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
            return result;
        }

        public string Update(MovementInfo movementInfo)
        {
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string strMovementID = string.Empty;
            try
            {
                MovementInfo oldMovementInfo = movementDA.GetMovementByID(dataBase, tran, movementInfo.MovementID, this.dataBaseID[0]);
                if (movementDA.UpdateMovement(dataBase, tran, movementInfo, whLoginID) > 0)
                {
                    strMovementID = movementInfo.MovementID;
                    ManPowerResourceInfo manpowerResourceInfo = movementInfo.ManPowerResourceInfo;
                    if (manpowerResourceDA.CheckManPowerResourceUnique(manpowerResourceInfo.OrderID, manpowerResourceInfo.OrderType, this.dataBaseID[0]))
                    {
                        manpowerResourceInfo.UpdatedDate = DateTime.Now;
                        manpowerResourceDA.UpdateManPowerResource(manpowerResourceInfo, this.dataBaseID[0]);
                    }
                    else
                    {
                        manpowerResourceInfo.OrderID = movementInfo.MovementID;
                        manpowerResourceInfo.CreatedDate = DateTime.Now;
                        manpowerResourceInfo.UpdatedDate = DateTime.Now;
                        manpowerResourceDA.InsertManPowerResource(manpowerResourceInfo, this.dataBaseID[0]);
                    }
                    new AuditDataBLL().InsertAuditData<MovementInfo>(dataBase, tran, oldMovementInfo, movementInfo, AuditAction.Update, this.pubParasInfo.UserID, "MOVEMENT", this.dataBaseID[0]);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return strMovementID;
        }
    }
}

